<template>		<!--该页面为测试记录页面-->
	<div>
		<el-breadcrumb separator="/"> <!--面包屑 -->
      <el-breadcrumb-item><i class="el-icon-s-home" style="margin-right: 15px;font-size: 16px"></i>试验记录</el-breadcrumb-item>
    </el-breadcrumb>
		<div class="info">
			<div style="height: 40px; margin-bottom: 10px">
			<el-button @click="otherDialogVisible = true" style="float: right;" type="primary">其他试验信息填写</el-button>
			<!-- 其他试验数据信息填写框 -->
			<el-dialog
			title="基本信息填写"
			:visible.sync="otherDialogVisible"
			width="830px">
			<el-form :model="otherRuleForm" :rules="otherRules" ref="otherRuleForm" label-width="80px" class="demo-ruleForm"  size="small">
				<el-row>
					<el-col :span="8">
						<el-form-item label="委试号" prop="number">
							<el-input placeholder="请输入委试号" v-model="otherRuleForm.number" size="small" clearable></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="温度" prop="temperature">
							<el-input :disabled="flag" placeholder="请输入温度" clearable v-model="otherRuleForm.temperature"><template slot="append" size="small">℃</template></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="大气压" prop="atmos">
							<el-input :disabled="flag" placeholder="请输入大气压" clearable v-model="otherRuleForm.atmos"><template slot="append" size="small">kPa</template></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row> 
					<el-col :span="8">
						<el-form-item label="相对湿度" prop="humidity">
							<el-input :disabled="flag" placeholder="请输入相对湿度" clearable v-model="otherRuleForm.humidity"><template slot="append" size="small">%RH</template></el-input>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<div style="font-size: 16px; color: #6565e7; padding-left: 5px; border-left: 3px solid #6565e7;">选择方案</div>
			<el-table stripe border
			:data="otherTableData"
			@row-click="rowClick"
			:row-class-name="tableRowClassName"
			:highlight-current-row="false"
			height="275"
			style="width: 100%; margin-top: 10px;">
			<el-table-column
				prop="plan_name"
				label="试验方案"
				width="180" align="center" show-overflow-tooltip>
			</el-table-column>
			<el-table-column
				prop="pk_ch_name"
				label="试品类型"
				width="180" align="center" show-overflow-tooltip>
			</el-table-column>
			<el-table-column
				prop="testKindStr"
				label="试验类型"
				width="180" align="center" show-overflow-tooltip>
			</el-table-column>
			<el-table-column
				prop="date"
				label="创建时间" align="center">
			</el-table-column>
			</el-table>
			<span slot="footer" class="dialog-footer">
				<el-button class="textBtn" @click="quxiao">取 消</el-button>
				<el-button type="primary" @click="sure">确 定</el-button>
			</span>
			</el-dialog>
			</div>
			<el-card shadow="always">
				<div slot="header" class="clearfix">
				<el-form ref="refForm" :model="searchContent" label-width="80px"  size="small">
            <el-row>
              <el-col :span="8">
                <el-form-item label="试验日期">
					<el-date-picker v-model="timeSelect" type="daterange" align="right" unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"  value-format="yyyy-MM-dd" style="width:100%"></el-date-picker>
                  <!-- <el-date-picker
					v-model="timeSelect" 
					type="daterange"
					align="right"
					start-placeholder="开始日期"
					end-placeholder="结束日期"
					:default-time="['00:00:00', '23:59:59']" 
				
					style="width: 100%"
					value-format="yyyy-MM-dd HH-mm-ss">
				  </el-date-picker> -->
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="委试号">
                  <el-input placeholder="请输入委试号" v-model="searchContent.testNumber" clearable size="medium"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="试验员">
                  <el-input placeholder="请输入试验员" v-model="searchContent.nickName" clearable size="medium"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="试品类型">
                  <el-select v-model="searchContent.pk_ch_name" placeholder="请选择试品类型" style="width: 100%" clearable>
                  <el-option
                    v-for="item in options"
                    :key="item.pk_id"
                    :label="item.pk_ch_name"
                    :value="item.pk_ch_name">
                  </el-option>
                </el-select>
                </el-form-item>
              </el-col>
              <el-col :offset="8" :span="8">
                <el-form-item style="float: right;">
                  <el-button type="primary"  @click="getAllTrialRecord" size="small">查询</el-button>
				  <el-button class="textBtn" @click="handleClick" size="small">重置</el-button>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
				</div>
			<!-- </el-card>
			<el-card shadow="always" style="margin-top: 30px"> -->
				<el-table stripe v-loading="dataLoading" :data="trialRecordData.slice((currentPage-1)*pagesize,currentPage*pagesize)" @sort-change='sortChange' style="width: 100%" >
					<el-table-column type="expand">
						<template slot-scope="props">
							<div>
								<span>试验方案名称：</span><span style="color: #6565e6">{{ props.row.plan_name }}</span>
							</div>
							<div style="margin:10px 0;">
								<span>试品模板名称：</span><span style="color: #6565e6">{{ props.row.tplt_name }}</span>
							</div>
							<div>
								<span>工 位 名 称 ：</span><span style="color: #6565e6">{{ props.row.station_name }}</span>
							</div>
						</template>
					</el-table-column>
					<el-table-column sortable="custom" align="center" prop="test_number" label="委试号" show-overflow-tooltip></el-table-column>
					<el-table-column sortable="custom" align="center"  prop="pk_ch_name" label="试品名称" show-overflow-tooltip></el-table-column>
					<el-table-column sortable="custom" align="center" prop="nickname" label="试验员" show-overflow-tooltip></el-table-column>
					<el-table-column sortable="custom" align="center" prop="testDate" label="试验日期" show-overflow-tooltip></el-table-column>
					<el-table-column sortable="custom" align="center" prop="review_status" label="审核状态" show-overflow-tooltip>
						<template slot-scope="scope">
							<span v-if="scope.row.review_status === 0" style="color: #03B915;">待审核</span>
							<span v-else-if="scope.row.review_status === 1" style="color: #6C59DD;">已通过</span>
							<span v-else-if="scope.row.review_status === null || scope.row.review_status === ''">--</span>
							<span v-else style="color: #D9001B;">驳回</span>
						</template>
					</el-table-column>
					<el-table-column sortable="custom" align="center" prop="review_name" label="审核人" show-overflow-tooltip>
						<template slot-scope="scope">
							<span v-if="scope.row.review_name">{{scope.row.review_name}}</span>
							<span v-else-if="scope.row.review_name === null">--</span>
							<span v-else>--</span>
						</template>
					</el-table-column>
					<el-table-column  sortable="custom" align="center" prop="reviewDate" label="审核日期" show-overflow-tooltip>
						<template slot-scope="scope">
							<span v-if="scope.row.reviewDate">{{scope.row.reviewDate}}</span>
							<span v-else-if="scope.row.reviewDate === null">--</span>
							<span v-else>--</span>
						</template>
					</el-table-column>
					<el-table-column align="center" label="操作" width="400">
						<template slot-scope="scope">
							<el-button class="global_add" type="text" @click="toTestRecordData(scope.row)" :disabled="btnList.see">查看</el-button>
							<el-divider direction="vertical"></el-divider>
							 <el-dropdown trigger="click" @command="ylHandleCommand">
								<span class="el-dropdown-link global_add">
									预览文件<i class="el-icon-arrow-down el-icon--right"></i>
								</span>
								<el-dropdown-menu slot="dropdown">
									<el-dropdown-item :command="[scope.row,'a']" :disabled="scope.row.review_status === null ? true : btnList.preview">预览记录</el-dropdown-item>
									<el-dropdown-item :command="[scope.row,'b']" :disabled="scope.row.review_status === null ? true : btnList.preview">预览报告</el-dropdown-item>
								</el-dropdown-menu>
							</el-dropdown>
							<el-divider direction="vertical"></el-divider>
							 <el-dropdown trigger="click" @command="xzHandleCommand">
								<span class="el-dropdown-link global_add">
									下载文件<i class="el-icon-arrow-down el-icon--right"></i>
								</span>
								<el-dropdown-menu slot="dropdown">
									<el-dropdown-item :command="[scope.row,'a']" :disabled="scope.row.review_status === null || scope.row.review_status === ''">下载记录</el-dropdown-item>
									<el-dropdown-item :command="[scope.row,'b']" :disabled="scope.row.review_status === null || scope.row.review_status === ''">下载报告</el-dropdown-item>
								</el-dropdown-menu>
							</el-dropdown>
							<el-divider direction="vertical"></el-divider>
              <el-dropdown trigger="click" @command="updateRecord">
								<span class="el-dropdown-link global_add">
									上传文件<i class="el-icon-arrow-down el-icon--right"></i>
								</span>
								<el-dropdown-menu slot="dropdown">
									<el-dropdown-item :command="[scope.row,'a']" :disabled="scope.row.review_status === null || scope.row.review_status === ''">上传记录</el-dropdown-item>
									<el-dropdown-item :command="[scope.row,'b']" :disabled="scope.row.review_status === null || scope.row.review_status === ''">上传报告</el-dropdown-item>
								</el-dropdown-menu>
							</el-dropdown>
						</template>
					</el-table-column>
				</el-table>
				<el-pagination class="pagination" background :hide-on-single-page="showPagination" :current-page.sync="currentPage" @size-change="handleSizeChange" :page-size="pagesize" layout="prev, pager, next" :total="trialRecordData.length"></el-pagination>
			</el-card>
		</div>
    <!-- 上传文件弹窗 -->
    <el-dialog
      title="上传文件"
      :visible.sync="FiledialogVisible"
      v-if="FiledialogVisible"
      width="40%"
      :before-close="RecordFileClose"
      >
      <div style="margin-bottom: 30px;margin-left: 290px;">
        <el-radio v-model="uploadFilesData.type" label="cn">中文</el-radio>
        <el-radio v-model="uploadFilesData.type" label="en">中英</el-radio>
      </div>
      <el-upload
        class="upload-demo"
        style="margin-left: 290px;"
        ref="upload"
        :limit="1"
        :action="uploadFiles"
        :data="uploadFilesData"
        accept=".doc,.docx,"
        :on-change="fileChange"
        :auto-upload="false"
        :on-error="uploadFileserror"
        :on-success="uploadFilesSuccess"
        >
        <div>
          <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
          <div slot="tip" class="el-upload__tip">只能上传DOC/DOCX文件</div>
        </div>
      </el-upload>
      <span slot="footer" class="dialog-footer">
        <el-button @click="RecordFileClose">取 消</el-button>
        <el-button type="primary" @click="saveRecordFile">确 定</el-button>
      </span>
    </el-dialog>
	</div>
</template>
<script>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 引入需要用到的第三方nodejs库，如日期计算等
// 需要先通过npm安装第三方组件包，然后在代码中使用
// npm install xxx 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// import moment from 'moment';
// import dayjs from 'dayjs';
// import Bus from '../../public/eventBus'; 
import { serverURL, gkServerURL } from '../../public/setting'
import roleBtn from '../../public/means'
import { base64 } from '../../public/base64'
import dayjs from 'dayjs'
export default {
	data() {
		var validateNumber = (rule, value, callback) => {
			const reg = /^[A-Za-z0-9]{0,}$/
			if (!reg.test(value)) {
			callback(new Error('请输入正确格式的委试号'));
			}
			callback();
      	};
		var validateTemperature = (rule, value, callback) => {
			const reg = /^[0-9.]{0,}$/
			if (!reg.test(value)) {
			callback(new Error('请输入正确格式的温度'));
			}
			callback();
      	};
		var validateAtmos = (rule, value, callback) => {
			const reg = /^[0-9.]{0,}$/
			if (!reg.test(value)) {
			callback(new Error('请输入正确格式的大气压'));
			}
			callback();
      	};
		var validateHumidity = (rule, value, callback) => {
			const reg = /^[0-9.]{0,}$/
			if (!reg.test(value)) {
			callback(new Error('请输入正确格式的相对湿度'));
			}
			callback();
      	};
		return {
			otherRuleForm: {
				number: '',
				temperature: '',
				atmos: '',
				humidity:''
			},
			flag: false,
			otherRules: {
				number: [
					{ required: true, message: '请输入委试号', trigger: 'blur' },
					 { validator: validateNumber, trigger: 'blur' }
				],
				temperature: [
					{ required: true, message: '请输入温度', trigger: 'blur' },
					 { validator: validateTemperature, trigger: 'blur' }
				],
				atmos: [
					{ required: true, message: '请输入大气压', trigger: 'blur' },
					 { validator: validateAtmos, trigger: 'blur' }
				],
				humidity: [
					{ required: true, message: '请输入相对湿度', trigger: 'blur' },
					 { validator: validateHumidity, trigger: 'blur' }
				],
			},
			otherTableData: [],
			otherDialogVisible: false,
			dataLoading: false,		//数据加载
			timeSelect: '',				//时间选择
			searchContent: {      //搜索条件
				testNumber:'',			//委试号
				nickName:'',			//试验员
        		pk_ch_name: ''
			},						
			trialRecordData: [],
			showPagination: true,
			currentPage: 1,
			pagesize: 10,
			options: [],
			menu_id: 14,
			btnList: {
				see: false,
				preview: false,
				download: false
			},
			tableRowIndex: -1,
			otherId: '',
			userId: '',
			trialRecordDatas: [],
      FiledialogVisible:false,
      // 上传文件路径
      uploadFiles:serverURL + '/trialRecord/uploadWordFile',
      uploadFilesData:{
        type:'cn'
      },
		};
	},
	methods: {
    fileChange(file){
      // console.log('file',file);
      this.uploadFilesData.fileName = file.name
    },
    // 上传文件 
    updateRecord (data){
      this.FiledialogVisible = true
      // 拼接发送路径
      if (data[1]==='a'){
        this.uploadFilesData.fileType = '记录'
        // this.uploadFiles += '' 
      } else if (data[1] === 'b'){
        this.uploadFilesData.fileType = '报告'
        // this.uploadFiles += ''
      } else {
        // this.uploadFiles = serverURL
      }
      this.uploadFilesData.testNumber = data[0].test_number
      this.uploadFilesData.testDate = data[0].testDate
      console.log('ddddd',data);
    },
    // 发送上传文件
    saveRecordFile(){
      // this.uploadFilesData = {
      //   fileType: '',// 记录/报告
      //   fileName:'',
      //   testNumber: '',// 委试号
      //   type: '',// 中文/英文
      // }
      this.$refs['upload'].submit();
    },
    // 关闭上传文件弹框
    RecordFileClose(){
      this.FiledialogVisible = false
      this.uploadFilesData={
        type:'cn'
      }
    },
    // 上传文件成功后的回调
    uploadFilesSuccess (){
      this.$message({
          message: '上传成功',
          type: 'success'
        });
      this.FiledialogVisible = false
      this.uploadFilesData={
        type:'cn'
      }
    },
    uploadFileserror() {
      this.$message.error('上传失败');
    },
		setTimeDef () {
			const end = new Date();
			const start = new Date();
			start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
			const startTime = dayjs(start).format('YYYY-MM-DD');
			const endTime = dayjs(end).format('YYYY-MM-DD');
			this.timeSelect = [startTime, endTime];
			console.info("||||||||||||||||||")
			console.info(this.timeSelect)
			this.getAllTrialRecord();
		},
		generalSort(attr, rev){
			//第一个参数传入表示排的是哪一列，第二个参数是升还是降排序
			if (rev == undefined) {
				rev = 1;
			} else {
				rev = (rev) ? 1 : -1;
			}
			return function (arry, barry) {
				arry = arry[attr];
				barry = barry[attr];
				if(arry === null){
					return rev * 1;
				}	
				if (arry < barry) {
					return rev * -1;
				}
				if (arry > barry) {
					return rev * 1;
				}
				return 0;
			}
		},
    // // 表格排序问题
	// 	sortChange(column){
	// 		this.currentPage = 1;
	// 		if (column.prop === 'testDate') {
	// 			this.trialRecordData = this.trialRecordData.sort(this.generalSort(column.prop, column.order === 'ascending'));
	// 		} else if (column.prop === 'reviewDate') {
	// 			this.trialRecordData = this.trialRecordData.sort(this.generalSort(column.prop, column.order === 'ascending'));
	// 		} else if (column.prop === 'test_number') {
	// 			this.trialRecordData = this.trialRecordData.sort(this.generalSort(column.prop, column.order === 'ascending'));
	// 		} else if (column.prop === 'pk_ch_name') {
	// 			this.trialRecordData = this.trialRecordData.sort(this.generalSort(column.prop, column.order === 'ascending'));
	// 		} else if (column.prop === 'nickname') {
	// 			this.trialRecordData = this.trialRecordData.sort(this.generalSort(column.prop, column.order === 'ascending'));
	// 		} else if (column.prop === 'review_status') {
	// 			this.trialRecordData = this.trialRecordData.sort(this.generalSort(column.prop, column.order === 'ascending'));
	// 		} else if (column.prop === 'review_name') {
	// 			this.trialRecordData = this.trialRecordData.sort(this.generalSort(column.prop, column.order === 'ascending'));
	// 		} else if (column.prop === 'review_date') {
	// 			this.trialRecordData = this.trialRecordData.sort(this.generalSort(column.prop, column.order === 'ascending'));
	// 		}
	// 		this.trialRecordData = this.trialRecordData.slice(0, this.pageSize) // 排序完显示到第一页
	// 	},
		//排序触发函数
    sortChange(column){
		// console.log(column,"sortchange")
	　　　　//点击向上【向下】激发排序　　
		this.currentPage = 1;
		// this.sortRule.order = column.order;
		// this.sortRule.prop = column.prop;
		if(column.order !== null && column.prop !== null){   //项目中要求所有列可排序，所以条件进行了判断！==null 即所有列 【如果项目中只有单个列【特定列】存在排序要求，出现混乱，colum.prop == "列的key"即可。】
			let index = column.prop;
			let data = [];
			let datas = [];
			for(let i = 0; i < this.trialRecordData.length; i++){  //this.tableDate 为表格总数据，后台请求的数据
				if(this.trialRecordData[i][index] === null){
					data.push(this.trialRecordData[i]);
				}else{
					datas.unshift(this.trialRecordData[i]);
				}
			}
			datas.sort(this.generalSort(column.prop, column.order === 'ascending'))
			console.log(datas);
			this.trialRecordData = datas.concat(data)
			// this.trialRecordData = this.trialRecordData.sort(this.generalSort(column.prop, column.order === 'ascending'));
		}
	　　//再点击向上【向下】恢复原始排序
		if(column.order === null){
			this.trialRecordData = this.trialRecordDatas;
		}
    	},
		quxiao() {
			this.$refs.otherRuleForm.resetFields()
			this.otherDialogVisible = false
			this.tableRowIndex = -1
		},
		async sure() {
			this.$refs.otherRuleForm.validate(async valid=>{
				if(!valid) {
					return
				}
				if(this.otherId === '') {
					this.$message.closeAll()
					this.$message.error('请先选择试验方案')
				}
				const loading = this.$loading({
				lock: true,
				text: '新增中，请稍后',
				spinner: 'el-icon-loading',
				background: 'rgba(0, 0, 0, 0.7)',
				customClass: 'londing_class'
				});
				const res = await this.$http.post('/trialRecord/creatOtherTestInstance',{testNumber: this.otherRuleForm.number, planId: this.otherId, ATM: this.otherRuleForm.atmos,RH: this.otherRuleForm.humidity, testUser: this.userId, T: this.otherRuleForm.temperature, date: dayjs().format('YYYY-MM-DD HH:mm:ss')}).catch(err=>err)
				console.log(res);
				if(res.code !== 200) {
					loading.close();
					return this.$message('新增失败！')
				}
				this.$message.success('新增成功！')
				loading.close();
				this.otherDialogVisible = false
				this.$refs.otherRuleForm.resetFields()
				this.tableRowIndex = -1
				this.getAllTrialRecord()
				this.getInfo()

				// 验证通过后的逻辑
				// this.otherDialogVisible = false
			})
		},
		keyupSubmit(){
        document.onkeydown=e=>{
          let _key=window.event.keyCode;
          if(_key===13){
            this.getAllTrialRecord()
          }
        }
      },
		rowClick(row, column, event) {
			this.tableRowIndex = this.getArrayIndex(this.otherTableData, row); // 获取当前点击行下标
			this.otherId = row.plan_id

		},
		tableRowClassName({ row, rowIndex }) {
		if (rowIndex === this.tableRowIndex) {
			return 'highlight-row'
		}
		return ''
		},
		// 获取一个元素在数组中的下标
		getArrayIndex(arr, obj) {
		var i = arr.length;
		while (i--) {
			if (arr[i] === obj) {
			return i;
			}
		}
		return -1;
		},
		handleClick(){
      this.searchContent.nickName = '',
      this.searchContent.testNumber = '',
      this.searchContent.pk_ch_name = '',
      this.timeSelect = ''

		},
		//日期确认触发函数
		filterByTime(){
			this.getTestRecordTotal();
			this.getTestRecordList();
		},
		handleSizeChange(val) {
      this.pagesize=val;
		},
		//测试方案输入
    onEnterToSearch(){
			this.getTestRecordTotal();
			this.getTestRecordList();
		},
		// async toTest(){
		// 	const ret = await this.$http.get("/trialRecord/toTest");
		// },
		
		//获取测试记录表格数据
		async getAllTrialRecord(){
			this.dataLoading = true;
			if(this.timeSelect === null){
        this.timeSelect = '';
      }
			const params = {
				startTime: this.timeSelect[0],
				endTime: this.timeSelect[1],
				'testNumber':this.searchContent.testNumber,
				'nickName':this.searchContent.nickName,
				'pkChName' : this.searchContent.pk_ch_name
			};
			const ret = await this.$http.get("/trialRecord/getAllTrialRecord",{params,});
			// ret.result.forEach(item => {
			// 	if(item.review_status === null) {
			// 		item.review_status = ''
			// 	}
			// });
			this.trialRecordData = ret.result;
			this.trialRecordDatas = ret.result;
			this.dataLoading = false;
		},
		async getProductKind() {
			const { result } = await this.$http.get('/testProdTemplate/getProductKind')
			this.options = result
		},
		//跳转至记录具体内容
		toTestRecordData(row){
			// console.log(row);
			// 添加判断 看跳转到哪一个试验详情页面
			let arr = row.test_kind.split(',')
			if(arr.includes('1') || arr.includes('2') || arr.includes('3')){
				this.$router.push({
					path: '/TestRecordData',
					query:{
						// 'sign': 'testRecord',
						 'planName': row.plan_name,
						'instanceId': row.instance_id,
						'testNumber': row.test_number,
						'beginTime': row.date,
						'duration': row.duration,
						pk_ch_name: row.pk_ch_name,
						tplt_name: row.tplt_name,
						review_status: row.review_status,
						testDate: row.testDate
						// 'statusName': row.statusName,
						// 'alarmCount': row.alarmCount
					}
				})
			}else  {
				this.$router.push({
					path: '/TestRecordDatas',
					query:{
						// 'sign': 'testRecord',
						 'planName': row.plan_name,
						'instanceId': row.instance_id,
						'testNumber': row.test_number,
						'beginTime': row.date,
						'duration': row.duration,
						pk_ch_name: row.pk_ch_name,
						tplt_name: row.tplt_name,
						review_status: row.review_status,
						testDate: row.testDate
						// 'statusName': row.statusName,
						// 'alarmCount': row.alarmCount
					}
				})
			}
		},
		 async ylHandleCommand(command) {
			 console.log(command);
        if(command[1] === 'a') {
			console.log('预览记录');
			const loading = this.$loading({
			lock: true,
			text: '加载中，请稍后',
			spinner: 'el-icon-loading',
			background: 'rgba(0, 0, 0, 0.7)',
			customClass: 'londing_class'
			});
			let res = await this.$http.get(`${gkServerURL}/trialRecord/previewOrDownload?instanceId=${command[0].instance_id}&testNumber=${command[0].test_number}&testDate=${command[0].testDate.split(' ')[0]}&fileType=记录&reviewStatus=${command[0].review_status}&reviewUser=${command[0].review_name}`)
      if (res.result === '[object Object]') {
				res = await this.$http.get(`${gkServerURL}/trialRecord/previewOrDownload?instanceId=${command[0].instance_id}&testNumber=${command[0].test_number}&testDate=${command[0].testDate.split(' ')[0]}&fileType=记录&reviewStatus=${command[0].review_status}&reviewUser=${command[0].review_name}`)	
			}
			if(res.code !== 200) {
				loading.close();
				this.$message.error('获取记录失败请稍后重试！')
			}else {
				loading.close();
				// this.$message.success('获取成功！')
				const url = serverURL+res.result.pdfFilePath
				// window.open('http://123.56.132.202:8012/onlinePreview?url='+encodeURIComponent(base64.encode(url)))
				window.open(url)
			}
			// console.log(result);
			// console.log(serverURL);
			// const url = serverURL+'/public/report/2021-3-AC-2000型高压控制台.docx'
			// window.open('http://123.56.132.202:8012/onlinePreview?url='+encodeURIComponent(base64.encode(url)))
		}else{
			const loading = this.$loading({
			lock: true,
			text: '加载中，请稍后',
			spinner: 'el-icon-loading',
			background: 'rgba(0, 0, 0, 0.7)',
			customClass: 'londing_class'
			});
			console.log('预览报告');
			let res = await this.$http.get(`${gkServerURL}/trialRecord/previewOrDownload?instanceId=${command[0].instance_id}&testNumber=${command[0].test_number}&testDate=${command[0].testDate.split(' ')[0]}&fileType=报告&reviewStatus=${command[0].review_status}&reviewUser=${command[0].review_name}`)	
			if (res.result === '[object Object]') {
				res = await this.$http.get(`${gkServerURL}/trialRecord/previewOrDownload?instanceId=${command[0].instance_id}&testNumber=${command[0].test_number}&testDate=${command[0].testDate.split(' ')[0]}&fileType=报告&reviewStatus=${command[0].review_status}&reviewUser=${command[0].review_name}`)	
			}
			if(res.code !== 200) {
				loading.close();
				this.$message.error('获取报告失败请稍后重试！')
			}else {
				console.log('111111',res.result);
				loading.close();
				// this.$message.success('获取成功！')
				const url = serverURL+res.result.pdfFilePath
				window.open(url)
				// window.open('http://123.56.132.202:8012/onlinePreview?url='+encodeURIComponent(base64.encode(url)))
			}
		}
      },
	  async xzHandleCommand(command) {
        if(command[1] === 'a') {
			console.log('记录');
			const loading = this.$loading({
			lock: true,
			text: '加载中，请稍后',
			spinner: 'el-icon-loading',
			background: 'rgba(0, 0, 0, 0.7)',
			customClass: 'londing_class'
			});
			let res = await this.$http.get(`${gkServerURL}/trialRecord/previewOrDownload?instanceId=${command[0].instance_id}&testNumber=${command[0].test_number}&testDate=${command[0].testDate.split(' ')[0]}&fileType=记录&reviewStatus=${command[0].review_status}&reviewUser=${command[0].review_name}`)
      if (res.result === '[object Object]') {
				res = await this.$http.get(`${gkServerURL}/trialRecord/previewOrDownload?instanceId=${command[0].instance_id}&testNumber=${command[0].test_number}&testDate=${command[0].testDate.split(' ')[0]}&fileType=记录&reviewStatus=${command[0].review_status}&reviewUser=${command[0].review_name}`)	
			}
			if(res.code !== 200) {
				loading.close();
				this.$message.error('获取记录失败请稍后重试！')
			}else {
				console.log(res.result);
				loading.close();
				this.$message.success('获取成功！')
				// location.href = `http://123.56.132.202:8010${res.result}`;
				let urls = `${serverURL}${res.result.docxFilePath}`
				console.log(1321,urls);
				location.href = `${serverURL}${res.result.docxFilePath}`;
				
			}
		}else{	
			const loading = this.$loading({
			lock: true,
			text: '加载中，请稍后',
			spinner: 'el-icon-loading',
			background: 'rgba(0, 0, 0, 0.7)',
			customClass: 'londing_class'
			});
			let res = await this.$http.get(`${gkServerURL}/trialRecord/previewOrDownload?instanceId=${command[0].instance_id}&testNumber=${command[0].test_number}&testDate=${command[0].testDate.split(' ')[0]}&fileType=报告&reviewStatus=${command[0].review_status}&reviewUser=${command[0].review_name}`)
			if (res.result === '[object Object]') {
				res = await this.$http.get(`${gkServerURL}/trialRecord/previewOrDownload?instanceId=${command[0].instance_id}&testNumber=${command[0].test_number}&testDate=${command[0].testDate.split(' ')[0]}&fileType=报告&reviewStatus=${command[0].review_status}&reviewUser=${command[0].review_name}`)
			}
			if(res.code !== 200) {
				loading.close();
				this.$message.error('获取报告失败请稍后重试！')
			}else {
				console.log(res.result);
				loading.close();
				this.$message.success('获取成功！')
				// location.href = `http://123.56.132.202:8010${res.result}`;
				// location.href = serverURL+res.result;
				location.href = `${serverURL}${res.result.docxFilePath}`;
				
			}
		}
      },
	  async getAllTpltInfo() {
		  const { result } = await this.$http.get('/trialRecord/getAllTpltInfo')
		  this.otherTableData = result
	  },
	  async getInfo() {
		  console.log(123);
		let date = dayjs().format('YYYY-MM-DD'); 
		const res = await this.$http.get(`/trialRecord/ifInputParams?date=${date}`)
		if(res.result) {
			this.otherRuleForm.atmos = res.result.ATM
			this.otherRuleForm.temperature = res.result.T
			this.otherRuleForm.humidity = res.result.RH
			this.flag = true
		}
	  }
	},
	mounted() {
		this.setTimeDef();
		this.getAllTpltInfo()
	},
	async created() {
		this.keyupSubmit()
		this.getProductKind()
		this.getInfo()
		const role_id = JSON.parse(sessionStorage.getItem('userInfo')).role_id;
		this.userId = JSON.parse(sessionStorage.getItem('userInfo')).user_id
		if(role_id){
		// 获取按钮权限状态
		let arr = await roleBtn.roleBtnList(role_id, this.menu_id)
		this.btnList = arr
    }
	}
};
</script>
<style lang="scss" scoped>
@import "./TrialRecord.scss";
</style>